<?php
// 后台用户模块
class NoteAction extends CommonAction {

	
	public function Note()
	{
		$note = M('web_note');
		$note = $note->Table('jym_web_note as a ,jym_web_note_class as b ,jym_web_user as c')->where('a.class=b.id AND a.inputer=c.id')->field('a.recommend,a.hot,a.status,a.sort,a.author,a.level,a.encrypt,a.title,a.id,b.name,c.username,c.nickname')->select();
		//echo $note->getLastSql();
		//print_r($note);
		//echo 123;
		//exit();
		//遍历等级
		foreach ($note as $key=>$v){
		$L = C("Levels");
			//print_r($L);
			foreach ($L as $kyes=>$vs){
				if($note[$key]['level'] == $vs['id']){
					$note[$key]['levels'] = $vs['name'];
					break;
				}
			}
		}
		$this->assign('note',$note);
		$this->display();
	}
	public function Noteadd()
	{
		$noteclass = M('web_note_class');
		$noteclass = $noteclass->where('status=1')->select();
		$this->assign('noteclass',$noteclass);
		$L = C("Levels");
		$Levels ='';
		foreach ($L as $key=>$v){
			$Levels .= '<option value="'.$v['id'].'">'.$v['name'].'</option>';
		}
		$this->assign('Levels',$Levels);
		$this->display();
	}
	public function Noteadds()
	{
		$note = M('web_note');
		$data['title'] = $this->_post('title');
		$data['keywords'] = $this->_post('keywords');
		$data['describe'] = $this->_post('describe');
		$data['content'] = $_POST['content'];
		$data['hot'] = $this->_post('hot');
		$data['recommend'] = $this->_post('recommend');
		$data['status'] = $this->_post('status');
		$data['author'] = $this->_post('author');
		$data['encrypt'] = $this->_post('encrypt');
		$data['class'] = $this->_post('class');
		$data['inputer'] = $this->_post('inputer');
		$data['sort'] = $this->_post('sort');
		$data['time'] = time();
		$data['times'] = time();
		$data['inputer'] = $this->Verifylogin();
		$data['encrypt'] = $this->_post('encrypt');
		$note = $note->add($data);
		if(false !== $note)
		{
			$this->admin_log('add','note','无','1');//日志文件
			$this->success('数据写入成功！');
		}
		else
		{
			$this->admin_log('add','note','无','0');//日志文件
			$this->error('数据写入错误！');
		}
	}
	public function Noteed()
	{
		if($id = $this->_get('id')){
			$note = M('web_note');
			$note = $note->Table('jym_web_note as a ,jym_web_note_class as b ,jym_web_user as c')->where('a.class=b.id AND a.inputer=c.id AND a.id='.$id)->find();
			$this->assign($note);
			$noteclass = M('web_note_class');
			$noteclass = $noteclass->where('status=1')->select();
			$this->assign('noteclass',$noteclass);
			$L = C("Levels");
			$Levels ='';
			foreach ($L as $key=>$v){
				if($v['id'] == $note['level']){
					$Levels .= '<option value="'.$v['id'].'" selected>'.$v['name'].'</option>';
				}else{
					$Levels .= '<option value="'.$v['id'].'">'.$v['name'].'</option>';
				}
			}
			$this->assign('Levels',$Levels);
			$this->display();
		}else{
			$this->error('非法访问！');
		}
	}
	public function Noteeds()
	{
		$this->display();
	}
	public function Notedel()
	{
		$this->display();
	}
	//事件分类处理
	public function Noteclass()
	{
		$noteclass = M('web_note_class');
		$noteclass = $noteclass->order('sort')->select();
		$this->assign('noteclass',$noteclass);
		$this->display();
	}
	
	public function Noteclassadd()
	{
		$this->display();
	}
	public function Noteclassadds()
	{
		$noteclass = M('web_note_class');
		$data['name'] = $this->_post('name');
		$data['sort'] = $this->_post('sort');
		$data['status'] = $this->_post('status');
		$noteclass = $noteclass->add($data);
		if(false !== $noteclass)
		{
			$this->admin_log('add','note_class','无','1');//日志文件
			$this->success('数据写入成功！');
		}
		else
		{
			$this->admin_log('add','note_class','无','0');//日志文件
			$this->error('数据写入错误！');
		}
	}
	public function Noteclassed()
	{
		if($id = $this->_get('id')){
			$noteclass = M('web_note_class');
			$noteclass = $noteclass->where('id='.$id)->find();
			$this->assign($noteclass);
			$this->display();
		}else{
			$this->error('非法提交！');
		}
	}
	public function Noteclasseds()
	{
		if($id = $this->_get('id')){
			$noteclass = M('web_note_class');
			$data['name'] = $this->_post('name');
			$data['sort'] = $this->_post('sort');
			$data['status'] = $this->_post('status');
			//print_r($data);
			$noteclass = $noteclass->where('id='.$id)->save($data);
			if(false !== $noteclass)
			{
				$this->admin_log('ed','note_class','无','1');//日志文件
				$this->success('数据写入成功！');
			}
			else
			{
				$this->admin_log('ed','note_class','无','0');//日志文件
				$this->error('数据写入错误！');
			}
		}else{
			$this->error('非法提交！');
		}
	}
	public function Noteclassdel()
	{
		if($id = $this->_get('id')){
			$noteclass = M('web_note_class');
			$noteclass = $noteclass->where('id='.$id)->delete();
			if(false !== $noteclass)
			{
				$this->admin_log('del','note_class','无','1');//日志文件
				$this->success('数据写入成功！');
			}
			else
			{
				$this->admin_log('del','note_class','无','0');//日志文件
				$this->error('数据写入错误！');
			}
		}else{
			$this->error('非法提交！');
		}
	}
}
?>